package com.xiaoshuidi.cloud.module.member.enums.coupon;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.baomidou.mybatisplus.annotation.IEnum;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Alex
 * @description 优惠券使用枚举
 * @date 2022/12/5 16:45
 */
@Getter
@AllArgsConstructor
public enum CouponUsageStatusEnum implements IEnum<Integer> {

	TO_BE_USED(1,"待使用"),
	VOIDED  (2,"已作废"),
	USED (3,"已使用"),
	EXPIRED(4,"已过期"),

	;
	@EnumValue
	private final Integer code;
	private final String desc;

	private static Map<Integer, CouponUsageStatusEnum> enumMap = new HashMap<>();

	static {
		CouponUsageStatusEnum[] values = CouponUsageStatusEnum.values();
		for (CouponUsageStatusEnum value : values) {
			enumMap.put(value.getCode(), value);
		}
	}

	@Override
	public Integer getValue() {
		return code;
	}

	public static CouponUsageStatusEnum getEnum(Integer code){
		return enumMap.get(code);
	}

	public static String getDesc(Integer code){
		CouponUsageStatusEnum couponUsageStatusEnum = getEnum(code);
		return couponUsageStatusEnum == null ? null : couponUsageStatusEnum.getDesc();
	}
}
